package com.linhh.mall.center.web.controller;

import com.github.pagehelper.PageInfo;
import com.linhh.mall.center.api.MemberInfoService;
import com.linhh.mall.center.common.pojo.BrandInfo;
import com.linhh.mall.center.common.pojo.MemberInfo;
import com.linhh.mall.center.common.util.HttpResult;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import tk.mybatis.mapper.entity.Example;

import java.lang.reflect.Member;
import java.util.List;

/**
 * 会员信息控制层
 * @Author linhh
 * @Date 2022 12 13 23 34
 **/
@RestController
@RequestMapping("/api")
public class MemberInfoController {

    @Reference
    private MemberInfoService memberInfoService;

    @GetMapping("/member")
    public HttpResult getAllMember(){
        List<MemberInfo> all = memberInfoService.getAllMemberInfo();
        return HttpResult.success(all);
    }

    /**
     * 分页查询会员信息列表
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getMember")
    public HttpResult getMember(@RequestParam(value = "page",defaultValue = "1") int page,@RequestParam(value = "size",defaultValue = "10")int size){
        PageInfo<MemberInfo> members = memberInfoService.getMember(page+1,size);
        return HttpResult.success(members);
    }
    @DeleteMapping("/deleteMember/{id}")
    public int deleteMemberInfo(@PathVariable Long id){
        return memberInfoService.deleteMemberInfo(id);
    }

    @PutMapping("/editMemberInfo")
    public int updateMemberInfo(@RequestBody MemberInfo memberInfo){
        return memberInfoService.updateMemberInfo(memberInfo);
    }

    @PostMapping("/addMember")
    public int addMemberInfo(@RequestBody MemberInfo memberInfo){
        System.out.println("addMemberInfo");
        return memberInfoService.addMemberInfo(memberInfo);
    }


}
